home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / os2 / wuz12.zip / Install.Cmd < prev    next >
OS/2 REXX Batch file  |  1994-05-11  |  15KB  |  471 lines

  1. /* Rexx install program */
  2. /* Donated to the public domain Feb. 19, 1994 by Scott Maxwell. */
  3.  
  4. /* Note: I believe this to be a pretty intelligent install routine. */
  5. /*       Please modify it and use it as you like.            */
  6.  
  7. Call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  8. Call SysLoadFuncs
  9.  
  10. parse arg args
  11. if Left(args,1) = '"' then do
  12.   parse var args '"' where '"' tempdir
  13.   tempdir = strip(tempdir)
  14. end
  15. else
  16.   parse var args where tempdir
  17.  
  18.  
  19. KeepCommandLineWindow = 1
  20. WaitForUnzip  = 1
  21. UnzipInCommandLineWindow = 1    /* KeepCommandLineWindow must be 1 for this */
  22.  
  23.   Say "Welcome to Workplace UnZip!"'0a'x
  24.  
  25.   Say "WUZ is a series of REXX functions to give you access to archive"
  26.   Say "files (including .ARC, .ARJ, .LZH, .TAR, .Z, .ZIP and .ZOO) from"
  27.   Say "the Workplace Shell or the command line."'0a'x
  28.  
  29. top:
  30.  
  31. ucnt = 1
  32. final = ''
  33. AutoMatic = 1
  34.  
  35. if where = '' then do
  36.   where = ''
  37.   path = Value('PATH',,'OS2ENVIRONMENT')
  38.  
  39.   i = 1
  40.   found = 0
  41.   dir. = ''
  42.   do forever
  43.     parse var path dir.i ';' path
  44.     if Right(dir.i,1) \= '\' then
  45.       dir.i = dir.i'\'
  46.     if SubStr(dir.i,2,1) = ':' then do
  47.       if Stream( dir.i'wuz.cmd', 'C', 'QUERY EXISTS' ) \= '' then do
  48.         found=i
  49.         Call LineIn dir.found'wuz.cmd'
  50.         Call LineIn dir.found'wuz.cmd'
  51.         Call LineIn dir.found'wuz.cmd'
  52.         Call LineIn dir.found'wuz.cmd'
  53.         old = LineIn(dir.found'wuz.cmd')
  54.         if Left(old,8) \= 'DestPath' then do
  55.           preamble = "A version of WUZ.CMD I don't recognize"
  56.       old = ''
  57.       end
  58.         else do
  59.           old = SubStr(old,13,Length(old)-13)
  60.       preamble = 'WUZ'
  61.           Call LineIn dir.found'wuz.cmd'
  62.           Call LineIn dir.found'wuz.cmd'
  63.           hold = LineIn(dir.found'wuz.cmd')
  64.           if Left(hold,24) = 'KeepCommandLineWindow = ',
  65.              & (SubStr(hold,25,1) = '0' | SubStr(hold,25,1) = '1') then
  66.             KeepCommandLineWindow = SubStr(hold,25,1)
  67.           hold = LineIn(dir.found'wuz.cmd')
  68.           if Left(hold,15) = 'WaitForUnzip = ',
  69.              & (SubStr(hold,16,1) = '0' | SubStr(hold,16,1) = '1') then
  70.             WaitForUnzip = SubStr(hold,16,1)
  71.           hold = LineIn(dir.found'wuz.cmd')
  72.           if Left(hold,27) = 'UnzipInCommandLineWindow = ',
  73.              & (SubStr(hold,28,1) = '0' | SubStr(hold,28,1) = '1') then
  74.             UnzipInCommandLineWindow = SubStr(hold,28,1)
  75.         end
  76.     Call LineOut dir.found'wuz.cmd'
  77.     if Stream( dir.found'Post-WUZ.cmd', 'C', 'QUERY EXISTS' ) \= '' then do
  78.       Call Linein(dir.found'Post-wuz.cmd')
  79.       Call Linein(dir.found'Post-wuz.cmd')
  80.       Call Linein(dir.found'Post-wuz.cmd')
  81.       final = Linein(dir.found'Post-wuz.cmd')
  82.       if Left(final,12)\='FinalCommand' | Right(final,3) = "=''" then
  83.         final=''
  84.       ucnt = 1
  85.       user.ucnt = Linein(dir.found'Post-wuz.cmd')
  86.       if Left(user.ucnt,11) = '/* ---- You' then
  87.       do ucnt=2 to 50
  88.         user.ucnt = Linein(dir.found'Post-wuz.cmd')
  89.         if Left(user.ucnt,12) = '/* ---- They' then leave
  90.       end
  91.     end
  92.     Call LineOut dir.found'Post-wuz.cmd'
  93.       end
  94.       i=i+1
  95.     end
  96.     if path='' then leave
  97.   end
  98.  
  99.   if found > 0 then
  100.   do forever
  101.     Say preamble "seems to be installed in" dir.found'0a'x
  102.     Say "0) Use the current copy (i.e. aborting this install)"
  103.     Say "1) Copy over the current version, keep current settings"
  104.     Say "2) Copy over the current version, change settings"
  105.     Say "3) Remove the current copy of WUZ and install somewhere else"
  106.     Say "4) Remove every last trace of WUZ from your computer"'0a'x
  107.     Call CharOut ,"What would you like to do: "
  108.     parse upper pull ans
  109.     if ans = 0 | ans = '' then exit(0)
  110.     if ans < 0 | ans > 4 then do
  111.       say '0a'x"Please answer either 0, 1, 2, 3, 4 or <RETURN>"
  112.       iterate
  113.     end
  114.  
  115.     if ans>=3 then do
  116.       say "Erasing:    wuz.cmd"
  117.       say "        wuz.ico"
  118.       say "        post-wuz.cmd"
  119.       say "        zipstrip.cmd"
  120.       say "        zip-dir.cmd"
  121.       say "        zip-dir.ico"
  122.       say "        fldzip.ico"
  123.       say "        fldunzip.ico"
  124.       say "        od.cmd"
  125.       say "        open-dir.cmd"
  126.       say "        wpset.cmd"
  127.       say "        kd.cmd"
  128.       say "        kill-dir.cmd from" dir.found'0a'x
  129.       Call SysFileDelete dir.found'wuz.cmd'
  130.       Call SysFileDelete dir.found'wuz.ico'
  131.       Call SysFileDelete dir.found'post-wuz.cmd'
  132.       Call SysFileDelete dir.found'zipstrip.cmd'
  133.       Call SysFileDelete dir.found'zip-dir.cmd'
  134.       Call SysFileDelete dir.found'zip-dir.ico'
  135.       Call SysFileDelete dir.found'fldzip.ico'
  136.       Call SysFileDelete dir.found'fldunzip.ico'
  137.       Call SysFileDelete dir.found'od.cmd'
  138.       Call SysFileDelete dir.found'open-dir.cmd'
  139.       Call SysFileDelete dir.found'wpset.cmd'
  140.       Call SysFileDelete dir.found'kill-dir.cmd'
  141.       Call SysFileDelete dir.found'kd.cmd'
  142.       Call SysDestroyObject '<WorkplaceUnZip>'
  143.       Call SysDestroyObject '<ZipDir>'
  144.       if ans = 4 then exit(1)
  145.     end      
  146.     if ans=1 then do
  147.       where = dir.found
  148.       AutoMatic = 1
  149.     end
  150.     if ans=2 then do
  151.       where = dir.found
  152.       AutoMatic = 0
  153.     end
  154.     leave
  155.   end
  156.   else
  157.     Say "Apparently, this is the first time you are installing WPS UnZip."
  158.   do while ans \=1 & ans \= 2
  159.     Say "There are two ways to install:"'0a'x
  160.     Say "1) Don't ask me any questions. Just do it!"
  161.     Say "2) Hey, I want to know what's going on.  Ask me everything."
  162.     Say "X) Actually, maybe I won't install right now."'0a'x
  163.     Call CharOut ,"Which would you like to do: "
  164.     parse upper pull ans
  165.     if ans = 'X' | ans = '' then exit(0)
  166.     if ans < 1 | ans > 2 then do
  167.       say '0a'x"Please answer either 0, 1, 2, 3 or <RETURN>"
  168.       iterate
  169.     end
  170.     if ans = 1 then
  171.       AutoMatic = 1
  172.     else
  173.       AutoMatic = 0
  174.     Call CharOut ,'0a'x
  175.   end
  176.  
  177.   if where = '' then do
  178.     i = i-1
  179.     root=FileSpec('Drive',Value('SYSTEM_INI',,'OS2ENVIRONMENT'))
  180.     if AutoMatic = 1 then do
  181.       where = root'\OS2'
  182.       Say "WUZ will be installed in" where
  183.     end
  184.     else do
  185.       Say "WUZ must be installed in a directory on your PATH:"'0a'x
  186.       base=1
  187.       nonbase=1
  188.       basedir. = ''
  189.       do j=1 to i
  190.         if Left(dir.j,6) = root'\OS2' | Left(dir.j,8) = root'\MMOS2' | dir.j = root'\' then do
  191.           basedir.base = dir.j
  192.       base = base+1
  193.         end
  194.         else do
  195.           dir.nonbase = dir.j
  196.           nonbase = nonbase+1
  197.         end
  198.       end
  199.       if base > 0 then do
  200.         k = 1
  201.         do j=nonbase to i
  202.           dir.j = basedir.k
  203.           k = k+1
  204.         end
  205.       end
  206.       dir.0 = i
  207.       tr = Trunc((i+1)/2)
  208.       do i=1 to tr
  209.         i2 = i+tr
  210.         build  = '('i')' dir.i
  211.         if dir.i2 \= '' then
  212.           build2 = '('i2')' dir.i2
  213.         else
  214.           build2 = ''
  215.         say insert(build,build2,,40)
  216.       end
  217.       Call CharOut ,'0a'x"Enter the number of your selection: "
  218.       parse pull ans
  219.       if ans > 0 & ans <= dir.0 then
  220.         where = dir.ans
  221.       else do
  222.         say "Invalid number.  Aborting"
  223.         exit(0)
  224.       end
  225.     end
  226.   end
  227.   tempdir = '\'
  228.   hold = directory()
  229. end
  230. else do
  231.   hold = directory()
  232.   where2 = directory(where)
  233.   if where2 = '\' then do
  234.     say "Unknown directory:" where
  235.     where = ''
  236.     Call Directory hold
  237.     Signal top
  238.   end
  239.   where = where2
  240.   if tempdir = '' then
  241.     tempdir = '\'
  242.   else
  243.     tempdir = directory(tempdir)
  244. end
  245.  
  246. do while tempdir = '\'
  247.   temp = ''
  248.   if found > 0 then temp = old
  249.   if temp = '' then
  250.     temp = Value('TMP',,'OS2ENVIRONMENT')
  251.     if temp = '' then
  252.       temp = Value('TEMP',,'OS2ENVIRONMENT')
  253.   if SubStr(temp,2,1) != ':' then temp = ''
  254.   slash = 1
  255.   if Right(temp,1) = '/' then
  256.     temp = Left(temp,Length(temp)-1)
  257.   do while slash > 0
  258.     slash = LastPos('/',temp)
  259.     if slash > 0 then
  260.       temp = Left(temp,slash-1)'\'Right(temp,slash+1)
  261.   end
  262.   if temp = '' then do
  263.     free = 0
  264.     drv = 'C:'
  265.     map = SysDriveMap('C:','LOCAL')
  266.     do i = 1 to words(map)
  267.       temp = SysDriveInfo(Word(map,i))
  268.       if Word(temp,2) > free then do
  269.         free = Word(temp,2)
  270.         drv = Word(map,i)
  271.       end
  272.     end
  273.     temp = Left(drv,2)'\Temp'
  274.   end
  275.   Say "WUZ will create a temporary directory for each archive it extracts."
  276.   if AutoMatic = 1 then
  277.     Say "Let's try putting the them in" temp'.'
  278.   else do
  279.     Call CharOut ,"Where should it create them? (<RETURN> for" temp") "
  280.     parse pull tempdir
  281.     if tempdir\='' then
  282.       temp = tempdir
  283.     do while Right(tempdir,2) == '\\' then
  284.       tempdir = Left(tempdir,Length(tempdir)-1)
  285.     end
  286.   end
  287.  
  288.   call Directory hold
  289.   tempdir = directory(temp)
  290.   if tempdir = '\' then do
  291.     if AutoMatic = 1 then
  292.       ans = 'Y'
  293.     else do
  294.       Call CharOut ,temp "does not exist.  Should I create it? "
  295.       parse upper pull ans
  296.     end
  297.     if Left(ans,1) = 'Y' then do
  298.       if SysMkDir(temp) then do
  299.         say "Can't create" temp
  300.         if AutoMatic = 1 then do
  301.           say "Using" Left(temp,3) "instead."
  302.           tempdir = Left(temp,3)
  303.         end
  304.       end
  305.       else
  306.         tempdir = temp
  307.     end
  308.   end
  309. end
  310. if Right(tempdir,1) \= '\' then tempdir = tempdir'\'
  311.  
  312. if AutoMatic = 0 then do
  313.   Say '0a'x"If you are used to DOS, you may want a command line."
  314.   Say "If you are a former MacIntosh user or a WPS purist, you probably don't."
  315.   if KeepCommandLineWindow = 1 then
  316.     ans = "Yes"
  317.   else
  318.     ans = "No"
  319.   Call CharOut ,"Would you like to keep a command line? (Return for" ans") "
  320.   parse upper pull keepAnswer
  321.   if Left(keepAnswer,1) = 'Y' then do
  322.     KeepCommandLineWindow = 1
  323.     UnzipInCommandLineWindow = 1
  324.   end
  325.   else if Left(keepAnswer,1) = 'N' then do
  326.     KeepCommandLineWindow = 0
  327.     UnzipInCommandLineWindow = 0
  328.   end
  329. end
  330.  
  331. call Directory hold
  332.  
  333. if where \= '.' then do
  334.   from = directory()
  335.   to = directory(where)
  336.   if to = '\' then do
  337.     say where': directory not found'
  338.     exit(1)
  339.   end
  340.   say '0a'x"Copying:    wuz.cmd"
  341.   say "        wuz.ico"
  342.   say "        post-wuz.cmd"
  343.   say "        zipstrip.cmd"
  344.   say "        zip-dir.cmd"
  345.   say "        zip-dir.ico"
  346.   say "        fldzip.ico"
  347.   say "        fldunzip.ico"
  348.   say "        od.cmd"
  349.   say "        open-dir.cmd"
  350.   say "        wpset.cmd"
  351.   say "        kd.cmd"
  352.   say "        kill-dir.cmd to "to
  353.  
  354.   Drive = Left(tempdir,2)
  355.   Call SysFileDelete 'wuz.cmd'
  356.   Call LineOut 'WUZ.cmd',linein(from'wuz.tpl')
  357.   Call LineOut 'wuz.cmd',linein(from'wuz.tpl')
  358.   Call LineOut 'wuz.cmd',linein(from'wuz.tpl')
  359.   Call LineIn from'wuz.tpl'
  360.   Call LineIn from'wuz.tpl'
  361.   Call LineIn from'wuz.tpl'
  362.   Call LineIn from'wuz.tpl'
  363.   Call LineIn from'wuz.tpl'
  364.   Call LineIn from'wuz.tpl'
  365.   Call LineIn from'wuz.tpl'
  366.   Call LineOut 'wuz.cmd',"Drive    = '"Drive"'"
  367.   Call LineOut 'wuz.cmd',"DestPath = '"tempdir"'"
  368.   Call LineOut 'wuz.cmd',"IconPath = '"to"'"
  369.   Call LineOut 'wuz.cmd',""
  370.   Call LineOut 'wuz.cmd',"KeepCommandLineWindow =" KeepCommandLineWindow
  371.   Call LineOut 'wuz.cmd',"WaitForUnzip =" WaitForUnzip
  372.   Call LineOut 'wuz.cmd',"UnzipInCommandLineWindow =" UnzipInCommandLineWindow"    /* KeepCommandLineWindow must be 1 for this */"
  373.   do while lines(from'wuz.tpl') > 0
  374.     Call LineOut 'wuz.cmd',LineIn(from'wuz.tpl')
  375.   end
  376.   Call LineOut 'wuz.cmd'
  377.   Call LineOut from'wuz.tpl'
  378.   '@copy' from'wuz.ico WUZ.ico > nul'
  379.  
  380.   if ucnt > 2 | final \= '' then do
  381.     Call SysFileDelete 'post-wuz.cmd'
  382.     Call LineOut 'Post-WUZ.cmd',linein(from'Post-wuz.tpl')
  383.     Call LineOut 'Post-WUZ.cmd',linein(from'Post-wuz.tpl')
  384.     Call LineOut 'Post-WUZ.cmd',linein(from'Post-wuz.tpl')
  385.     Say ''
  386.     if final \= '' then do
  387.       Say "Preserving FinalCommand from" where"Post-WUZ.CMD"
  388.       Say final
  389.       Call LineIn from'Post-wuz.tpl'
  390.       Call LineOut 'Post-WUZ.cmd',final
  391.     end
  392.     else
  393.       Call LineOut 'Post-WUZ.cmd',linein(from'Post-wuz.tpl')
  394.     if ucnt > 2 then do
  395.       Say "Preserving user lines from" where"Post-WUZ.CMD"
  396.       Call LineIn from'Post-wuz.tpl'
  397.       Call LineIn from'Post-wuz.tpl'
  398.       do i=1 to ucnt
  399.         Call LineOut 'Post-WUZ.cmd',user.i
  400.       end
  401.     end
  402.     else do
  403.       Call LineOut 'Post-WUZ.cmd',linein(from'Post-wuz.tpl')
  404.       Call LineOut 'Post-WUZ.cmd',linein(from'Post-wuz.tpl')
  405.     end
  406.     do while lines(from'Post-WUZ.tpl') > 0
  407.       Call LineOut 'Post-WUZ.cmd',LineIn(from'post-wuz.tpl')
  408.     end
  409.     Call LineOut 'Post-wuz.cmd'
  410.     Call LineOut 'Post-wuz.tpl'
  411.   end
  412.   else
  413.     '@copy' from'post-wuz.tpl Post-WUZ.Cmd > nul'
  414.  
  415.   '@copy' from'zipstrip.cmd > nul'
  416.   Call SysFileDelete 'zip-dir.cmd'
  417.   Call LineOut 'Zip-Dir.cmd',linein(from'zip-dir.tpl')
  418.   Call LineOut 'zip-dir.cmd',linein(from'zip-dir.tpl')
  419.   Call LineOut 'zip-dir.cmd',linein(from'zip-dir.tpl')
  420.   Call LineIn from'zip-dir.tpl'
  421.   Call LineOut 'zip-dir.cmd',"IconPath = '"to"'"
  422.   do while lines(from'zip-dir.tpl') > 0
  423.     Call LineOut 'zip-dir.cmd',LineIn(from'zip-dir.tpl')
  424.   end
  425.   Call LineOut 'zip-dir.cmd'
  426.   Call LineOut from'zip-dir.tpl'
  427.   '@copy' from'zip-dir.ico > nul'
  428.   '@copy' from'fldzip.ico > nul'
  429.   '@copy' from'fldunzip.ico > nul'
  430.   '@copy' from'open-dir.cmd > nul'
  431.   '@copy' from'open-dir.cmd od.cmd > nul'
  432.   '@copy' from'wpset.cmd > nul'
  433.   '@copy' from'kill-dir.cmd > nul'
  434.   '@copy' from'kill-dir.cmd kd.cmd > nul'
  435.   Call Directory from
  436. end
  437. else
  438.   to = directory()
  439.  
  440. Call SysDestroyObject '<WorkplaceUnZip>'
  441. Call SysCreateObject "WPProgram", "WPS Unzip", "<WP_DESKTOP>",,
  442.     "OBJECTID=<WorkplaceUnZip>;PROGTYPE=WINDOWABLEVIO;EXENAME="to"wuz.cmd;ASSOCFILTER=*.arc,*.arj,*.lzh,*.tar,*.z,*.zif,*.zip,*.zoo;SET=WUZMIN="keepAnswer
  443. Call SysDestroyObject '<ZipDir>'
  444. here = directory()
  445. Call SysCreateObject "WPProgram", "Zip Directory", "<WP_DESKTOP>",,
  446.     "OBJECTID=<ZipDir>;PROGTYPE=WINDOWABLEVIO;EXENAME="to"zip-dir.cmd"
  447.  
  448. Say '0a'x"Workplace UnZip v1.1 has been successfully installed."
  449. Say "Try it out and see if you like it.  If you do, I would appreciate"
  450. Say "a small cash donation of $20 or at least a note telling me what"
  451. Say "you think.  My Usenet address is scott.maxwell@channel1.com."
  452. Say "Any money should go to:"
  453. Say "                         Patricia Maxwell"
  454. Say "                         1587 E. Modesto Ave."
  455. Say "                         Camarillo, CA 93010 U.S.A."'0a'x
  456.  
  457. Say "You may also rerun Install.Cmd to uninstall."
  458. Say "For more information about Workplace UnZip, read ReadMe.WUZ and WUZ.Doc."
  459. exit(0)
  460.  
  461. Directory: procedure
  462.   arg Name
  463.   Name = Strip(Name,,'"')
  464.   if Length(Name) > 3 then
  465.     if Right(Name,1) = '\' then
  466.       Name = Left(Name,LENGTH(Name)-1)
  467.   n = 'DIRECTORY'(Name)
  468.   if Right(n,1) \= '\' then
  469.     n = n'\'
  470. return n
  471.